package com.invengo.module_check.ui.fragment.home;

import android.graphics.drawable.Drawable;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.databinding.ObservableBoolean;
import androidx.databinding.ObservableField;

import com.invengo.module_check.data.entity.FeatureBean;

import me.goldze.mvvmhabit.base.ItemViewModel;
import me.goldze.mvvmhabit.binding.command.BindingCommand;

public class HomeItemViewModel extends ItemViewModel<HomeViewModel> {
    public ObservableField<String> featureName = new ObservableField<>();
    public ObservableField<String> featurePath = new ObservableField<>();
    //    public ObservableField<Integer> featureIcon = new ObservableField<>();
    public ObservableBoolean isOpen = new ObservableBoolean();
    FeatureBean featureBean;
    public Drawable drawableImg;

    public HomeItemViewModel(@NonNull HomeViewModel viewModel, FeatureBean featureBean) {
        super(viewModel);
        this.featureBean = featureBean;
        this.featureName.set(featureBean.getName());
        drawableImg = ContextCompat.getDrawable(viewModel.getApplication(), featureBean.getActionArgs().getIcon());
        this.isOpen.set(featureBean.isOpen());
    }

    public BindingCommand onItemClick = new BindingCommand(() -> {
        //点击之后将逻辑转到activity中处理
        viewModel.itemClickEvent.setValue(featureBean);
    });
}